# Contributor: Alex Dowad <alexinbeijing@gmail.com>
# Maintainer: Alex Dowad <alexinbeijing@gmail.com>
pkgname=lua-luaphonenumber
pkgver=1.0.1
pkgrel=2
_gitrev=465463ae0735c91e31854781ffe0f9fafc717482
pkgdesc="Lua bindings for libphonenumber"
url="https://github.com/singlecomm/luaphonenumber"
arch="all"
license="MIT"
depends="libphonenumber"
makedepends="libphonenumber-dev"
options="!check" # Upstream does not have any test suite
source="$pkgname-$pkgver.tar.gz::https://github.com/singlecomm/luaphonenumber/archive/$_gitrev.tar.gz"
builddir="$srcdir/luaphonenumber-$_gitrev"

_luaversions="5.1 5.2 5.3 5.4"
for _v in $_luaversions; do
	makedepends="$makedepends lua$_v-dev"
	subpackages="$subpackages lua$_v-${pkgname#lua-}:_subpackage"
done

prepare() {
	default_prepare

	local lver; for lver in $_luaversions; do
		cp -r "$builddir" "$builddir-$lver"
	done
}

build() {
	local lver; for lver in $_luaversions; do
		msg "Building for Lua $lver..."

		cd "$builddir-$lver"
		make LUA_VERSION=$lver CXXFLAGS="$CXXFLAGS -std=c++17 -Wall -fPIC"
	done
}

package() {
	mkdir -p "$pkgdir"
	local lver; for lver in $_luaversions; do
		install -m 755 -D "$builddir-$lver"/luaphonenumber.so \
			"$pkgdir"/usr/lib/lua/$lver/luaphonenumber.so
	done
}

_subpackage() {
	local lver="${subpkgname:3:3}"
	pkgdesc="Lua $lver bindings for libphonenumber"
	depends="lua$lver"
	install_if="$pkgname=$pkgver-r$pkgrel lua$lver"
	amove usr/lib/lua/$lver
}

sha512sums="
f53768da7ac8b900f26aa5f0b9f9f22530732eae342f46a44ee7f21051a6081c4e6f3cf76267345b559267b3301af0c05872cf9c2cf082448c00201700f06dd7  lua-luaphonenumber-1.0.1.tar.gz
"
